package com.yuanrui.interview.server.controller;

import com.alibaba.nacos.shaded.com.google.common.base.Preconditions;
import com.yuanrui.interview.api.common.Result;
import com.yuanrui.interview.api.req.InterviewReq;
import com.yuanrui.interview.api.vo.InterviewVO;
import com.yuanrui.interview.server.service.InterviewHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/interview/")
public class InterviewController {

    @Resource
    private InterviewHistoryService interviewHistoryService;


    @RequestMapping("test")
    public String test() {
        return "test";
    }

    /**
     * 分析简历
     */
    @RequestMapping("analyse")
    public Result<InterviewVO> analyse(@RequestBody InterviewReq req){

        try {
            if (log.isDebugEnabled()) {
                log.debug("analyse req:{}", req);
            }
            Preconditions.checkNotNull(req.getUrl(), "url不能为空");
            Preconditions.checkNotNull(req.getEngine(), "engine不能为空");
            return Result.ok(interviewHistoryService.analyse(req));
        } catch (Exception e) {
            log.error("analyse error", e);
            return Result.fail(e.getMessage());
        }
    }
}
